package cli

import (
	"fmt"
	"strconv"
)

const (
	Prefix = "\033["
	Suffix = "m"
)

const Default = Prefix + "0" + Suffix

const (
	None = iota
	HeightLight
	_
	_
	UnderLine
	Blink
	_
	Reverse
	Hide
)

const (
	Black = iota + 30
	Red
	Green
	Yellow
	Blue
	Purple
	Cyan
	White
)

const (
	LightRed = iota + 91
	LightGreen
	LightYellow
	LightBlue
	LightPurple
	LightCyan
)

const (
	BlackBackground = iota + 40
	RedBackground
	GreenBackground
	YellowBackground
	BlueBackground
	PurpleBackground
	CyanBackground
	WhiteBackground
)

type CPrintParams struct {
	FontColor       int
	BackgroundColor int
	Special         int
}

func CSprint(text string, params CPrintParams) (raw string) {
	fontColor := params.FontColor
	bgColor := params.BackgroundColor
	special := params.Special
	raw += fmt.Sprint(Prefix + strconv.Itoa(special) + ";" + strconv.Itoa(bgColor) + ";" + strconv.Itoa(fontColor) + "m")
	raw += fmt.Sprint(text)
	raw += fmt.Sprint(Default)
	return raw
}

func CSprintf(text string, params CPrintParams, args ...interface{}) string {
	return fmt.Sprintf(CSprint(text, params), args...)
}

func CPrint(text string, params CPrintParams) {
	fmt.Print(CSprint(text, params))
}

func CPrintln(text string, params CPrintParams) {
	fmt.Println(CSprint(text, params))
}

func CPrintf(text string, params CPrintParams, args ...interface{}) {
	fmt.Printf(CSprintf(text, params, args...))
}
